﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ContadorDeHoras.DTO
{
    public class DiaDTO
    {

        public DateTime Dia { get; set; }
        public DateTime ManhaInicio { get; set; }
        public DateTime ManhaFim { get; set; }
        public DateTime TardeInicio { get; set; }
        public DateTime TardeFim { get; set; }

        public DiaDTO(DateTime manhaI, DateTime manhaF, DateTime tardeI, DateTime tardeF)
        {
            this.Dia = DateTime.Now;
            this.ManhaInicio = manhaI;
            this.ManhaFim = manhaF;
            this.TardeInicio = tardeI;
            this.TardeFim = tardeF;
        }

        public DiaDTO(DateTime dia, DateTime manhaI, DateTime manhaF, DateTime tardeI, DateTime tardeF)
        {
            this.Dia = dia;
            this.ManhaInicio = manhaI;
            this.ManhaFim = manhaF;
            this.TardeInicio = tardeI;
            this.TardeFim = tardeF;
        }

        public TimeSpan calculaTempoTotal()
        {
            return (ManhaFim.Subtract(ManhaInicio)).Add(TardeFim.Subtract(TardeInicio));
        }

        public TimeSpan calculaTempoExtra()
        {
            if (Dia.DayOfWeek != DayOfWeek.Saturday && Dia.DayOfWeek != DayOfWeek.Sunday)
            {
                TimeSpan t1 = calculaTempoTotal();
                TimeSpan t2 = new TimeSpan(8, 48, 0);
                return (t1 > t2 ? t1.Subtract(t2) : t2.Subtract(t1).Negate());
            }
            else
            {
                return calculaTempoTotal();
            }
        }

    }
}
